package cn.edu.sdjzu.xg.eagle.service.impl;

import cn.edu.sdjzu.xg.eagle.entities.Announcement;
import cn.edu.sdjzu.xg.eagle.mapper.AnnouncementMapper;
import cn.edu.sdjzu.xg.eagle.service.inface.AnnouncementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.List;

@Service
public class AnnouncementImpl implements AnnouncementService {

    @Autowired
    private AnnouncementMapper announcementMapper;

    @Override
    public String addAnnouncement(Announcement announcement) throws SQLException {
        if (announcementMapper.addAnnouncement(announcement)) {
            return "添加公告成功";
        }
        return "添加公告失败";
    }

    @Override
    public String deleteAnnouncement(int id) throws SQLException {
        if (announcementMapper.deleteAnnouncement(id)) {
            return "删除公告成功";
        }
        return "删除公告失败";
    }

    @Override
    public String updateAnnouncement(Announcement announcement) throws SQLException {
        if (announcementMapper.updateAnnouncement(announcement)) {
            return "更新公告成功";
        }
        return "更新公告失败";
    }

    @Override
    public Announcement findAnnouncementById(int id) throws SQLException {
        return announcementMapper.findAnnouncementById(id);
    }

    @Override
    public List<Announcement> findAllAnnouncements() throws SQLException {
        return announcementMapper.findAllAnnouncements();
    }
}